package edu.se.jai.lesson05nacos;

import edu.se.jai.lesson05nacos.config.AppConfig;
import edu.se.jai.lesson05nacos.config.DatabaseConfig;
import edu.se.jai.lesson05nacos.config.RedisConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@Slf4j
public class Lesson05Application implements CommandLineRunner {

    @Autowired
    private AppConfig appConfig;

    @Autowired
    private DatabaseConfig databaseConfig;

    @Autowired
    private RedisConfig redisConfig;

    public static void main(String[] args) {
        SpringApplication.run(Lesson05Application.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        printAllConfigurations();
    }

    /**
     * 打印所有配置信息
     */
    public void printAllConfigurations() {
        log.info("🚀 ===== Nacos配置管理演示系统启动成功 =====");
        log.info("📋 ===== 当前所有配置信息 =====");
        
        // 应用配置信息
        log.info("🔧 应用配置信息:");
        log.info("  📝 欢迎消息: {}", appConfig.getBusiness().getWelcomeMessage());
        log.info("  👥 最大用户数: {}", appConfig.getBusiness().getMaxUsers());
        log.info("  ✅ 启用注册: {}", appConfig.getBusiness().getEnableRegistration());
        log.info("  🌐 默认语言: {}", appConfig.getBusiness().getDefaultLanguage());
        log.info("  📊 启用日志: {}", appConfig.getFeature().getEnableLog());

        // 数据库配置信息
        log.info("🗄️ 数据库配置信息:");
        log.info("  🔗 数据库URL: {}", databaseConfig.getUrl());
        log.info("  🔢 最大连接数: {}", databaseConfig.getMaxConnections());

        // Redis配置信息
        log.info("🔴 Redis配置信息:");
        log.info("  🏠 Redis主机: {}", redisConfig.getHost());
        log.info("  🚪 Redis端口: {}", redisConfig.getPort());

        log.info("📋 ===== 配置信息打印完成 =====");
        log.info("🔥 配置热更新已启用，可通过Nacos控制台修改配置");
        log.info("🌐 Nacos控制台: http://127.0.0.1:8848/nacos");
        log.info("🚀 ===== 系统就绪，开始监听配置变更 =====");
    }
}

